// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()

// 时间戳转日期
const formatTimestamp = (timestamp) => {
    let nowDate = new Date(timestamp*1000);
    let month = (1 + nowDate.getMonth()) < 10 ? ('0' + (1 + nowDate.getMonth())) : (1 + nowDate.getMonth());
    let date = nowDate.getDate() < 10 ? ('0' + nowDate.getDate()) : 1 + nowDate.getDate();
    return nowDate.getFullYear() + '-' + month + '-' + date;
}

// 云函数入口函数
exports.main = async (event, context) => {
    var stepInfoList = event.weRunData.data.stepInfoList;
    // 将时间戳转成正常的日期格式
    stepInfoList.forEach(item => {
        item.timestamp = formatTimestamp(item.timestamp);
    })
    return stepInfoList;
}